import { _decorator, Component, Enum, JsonAsset, Node } from 'cc';
import { BUYTYPE, ITEMTYPE, NUMBER } from './GameConstant';
import PrefsUtil from '../AshFramework/Utils/PrefsUtil';
import { PrefsManager } from './PrefsManager';
const { ccclass, property } = _decorator;

@ccclass('Item')
export class Item extends Component {

    @property({ type: Enum(ITEMTYPE) })
    ItemType: ITEMTYPE = ITEMTYPE.PF;

    @property({ type: Enum(NUMBER) })
    ItemNumber: NUMBER = NUMBER.NUMBER1;

    @property({ type: Boolean })
    IsNormal: Boolean = false;

    @property({ type: Enum(BUYTYPE) })
    BuyType: BUYTYPE = BUYTYPE.VIDEO;

    @property
    Price: number = 0;

    Checked: Node = null;
    Have: Node = null;
    Bottom: Node = null;
    Luck: Node = null;
    IsHave: boolean = true;//是否拥有
    IsUnluck: boolean = false;//挂饰是否解锁

    protected onLoad(): void {
        this.Checked = this.node.getChildByName("选中框");
        this.Have = this.node.getChildByName("对勾");
        if (this.IsNormal) return;
        this.Bottom = this.node.getChildByName("底");
        if (this.ItemType == ITEMTYPE.GS) {
            this.Luck = this.node.getChildByName("Luck");
        }
    }

    isHave(have: boolean = true) {
        if (this.IsNormal) return;
        this.IsHave = have;
        this.Checked.active = false;
        this.Have.active = false;
        this.Bottom.active = !have;
    }

    /**
     * 
     * @param isChecked Item是否被选中
     */
    checked(isChecked: boolean) {
        this.Have.active = isChecked;
    }

    click(isClick: boolean) {
        this.Checked.active = isClick;
    }

    buy() {
        this.IsHave = true;
    }

    isUnluck(unluck: boolean = true) {
        if (this.IsNormal) return;
        this.IsUnluck = unluck;
        this.Luck.active = !unluck;
    }

}


